package com.sxfq.loansupermarket.backsystem.modular.guest.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.sxfq.loansupermarket.backsystem.core.shiro.ShiroKit;
import com.sxfq.loansupermarket.backsystem.core.util.StringUtil;
import com.sxfq.loansupermarket.backsystem.modular.guest.dao.GuestDao;
import com.sxfq.loansupermarket.backsystem.modular.guest.service.GuestService;
import com.sxfq.loansupermarket.backsystem.modular.guest.entity.GuestRevisitInfo;
import com.sxfq.loansupermarket.backsystem.modular.guest.entity.SearchGuestRevisitInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
@Transactional
public class GuestServiceImpl implements GuestService {
    @Autowired
    private GuestDao dao;

    public List<GuestRevisitInfo> selectPageListByRevisit(Page<GuestRevisitInfo> page, SearchGuestRevisitInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getReach())) {
            params.put("reach", searchInfo.getReach());
        }
        if (StringUtil.isNotEmpty(searchInfo.getRevisitStatus())) {
            params.put("revisitStatus", searchInfo.getRevisitStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStartRevisitTime())) {
            params.put("startRevisitTime", searchInfo.getStartRevisitTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndRevisitTime())) {
            params.put("endRevisitTime", searchInfo.getEndRevisitTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStartTime())) {
            params.put("startTime", searchInfo.getStartTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndTime())) {
            params.put("endTime", searchInfo.getEndTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStartUpdateTime())) {
            params.put("startUpdateTime", searchInfo.getStartUpdateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndUpdateTime())) {
            params.put("endUpdateTime", searchInfo.getEndUpdateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getFollowStatus())) {
            params.put("followStatus", searchInfo.getFollowStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getConsumptionStatus())) {
            params.put("consumptionStatus", searchInfo.getConsumptionStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getRevisit())) {
            params.put("revisit", searchInfo.getRevisit());
        }
        params.put("outpatientName", ShiroKit.getUser().getOutpatientName());
        params.put("tableName", ShiroKit.getUser().getCustomer_info());
        params.put("startIndex", searchInfo.getStartIndex());
        params.put("limitIndex", searchInfo.getLimitIndex());
        return dao.selectPageListByRevisit(page, params);
    }

    @Override
    public int getQueryPagesRevisitCount(Page<GuestRevisitInfo> page, SearchGuestRevisitInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getReach())) {
            params.put("reach", searchInfo.getReach());
        }
        if (StringUtil.isNotEmpty(searchInfo.getRevisitStatus())) {
            params.put("revisitStatus", searchInfo.getRevisitStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStartRevisitTime())) {
            params.put("startRevisitTime", searchInfo.getStartRevisitTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndRevisitTime())) {
            params.put("endRevisitTime", searchInfo.getEndRevisitTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStartTime())) {
            params.put("startTime", searchInfo.getStartTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndTime())) {
            params.put("endTime", searchInfo.getEndTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getStartUpdateTime())) {
            params.put("startUpdateTime", searchInfo.getStartUpdateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndUpdateTime())) {
            params.put("endUpdateTime", searchInfo.getEndUpdateTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getFollowStatus())) {
            params.put("followStatus", searchInfo.getFollowStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getConsumptionStatus())) {
            params.put("consumptionStatus", searchInfo.getConsumptionStatus());
        }
        if (StringUtil.isNotEmpty(searchInfo.getRevisit())) {
            params.put("revisit", searchInfo.getRevisit());
        }
        params.put("outpatientName", ShiroKit.getUser().getOutpatientName());
        params.put("tableName", ShiroKit.getUser().getCustomer_info());
        return dao.getQueryPagesRevisitCount(page, params);
    }
}